package com.lnu.information.controller;

import com.lnu.information.biz.CompanyBiz;
import com.lnu.information.dto.*;
import com.lnu.information.util.ValidateUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author : jian.zhang-2
 * @description:
 * @date : Create in 10:18 AM 2022/2/16
 * @modified By :
 */
@RestController
@RequestMapping("/api")
@Api("Swagger相关测试API")
public class QueryController {

    @Resource
    private CompanyBiz companyBiz;

    @GetMapping
    @RequestMapping("/hello")
    public String index(){
        return "hello";
    }

    @PostMapping
    @ApiOperation(value = "单表查询")
    @RequestMapping("/{tableName}")
    @ResponseBody
    public QueryCompanyResponseDTO queryTableData(@PathVariable String tableName, @RequestBody QueryCompanyRequestDTO queryCompanyRequestDTO){
        //1.校验参数
        ValidateUtil.checkRequestParam(tableName, "表名");
        ValidateUtil.checkTableName(tableName);
        ValidateUtil.checkParamByTableName(tableName, queryCompanyRequestDTO);
        return companyBiz.queryTableData(tableName, queryCompanyRequestDTO);
    }

    @PostMapping
    @ApiOperation(value = "关联表查询")
    @RequestMapping("/join/company&company_listedcompany_toptencurrentshareholders")
    @ResponseBody
    public QueryCompanyResponseDTO queryJoinTableData(@RequestBody QueryCompanyTopTenCurrentShareHoldersRequestDto queryCompanyRequestDTO){
        //1.校验参数
        ValidateUtil.checkRequestParam(queryCompanyRequestDTO.getCompanyId(), "企业ID");
        return companyBiz.queryJoinTableData(queryCompanyRequestDTO);
    }
}
